/*
 *  $Id: Aeromancy.cs 1051 2010-05-18 22:10:41Z thenn.erannor $
 *	This file is a part of Ragima CCG.
 *	(C) 2008 Ragima development group.
 *
 *	Licensed under the terms of the GNU GPL License version 2.
 *
 */

namespace Ragima.Cards001.Air.Spells {
    public class Aeromancy: TargetEnchantmentCard<Creature> {
        public Aeromancy(): base("001_a_s_aeromancy") {
            Level = CompleteLevel.ReadyForTest;
            Element = ElementType.Air;
            Value = 100;
            Target = CreatureTarget.Both;
            AddManaCost(ElementType.Air, 2);
        }

        protected override EnchantmentAffect CreateEnchantment() {
            return new AeromancyAffect();
        }

        private class AeromancyAffect: EnchantmentAffect<Aeromancy> {
            public override void SetAffect() {
                base.SetAffect();
                LocalSummary.OnAfterDamage += Damage;
            }
            public override void ResetAffect() {
                base.ResetAffect();
                LocalSummary.OnAfterDamage -= Damage;
            }

            private void Damage(AbstractObject target, DamageInfo damage) {
                if (target.HasFlag<AeromancyBlockAffect>()) return;
                Affect affect = new AeromancyBlockAffect();
                target.AddAffect(affect);
                target.DamageBy(NewDamage(DamageType.MagicAttack, 1));
                target.RemoveAffect(affect);
            }
        }

        private class AeromancyBlockAffect: FlagAffect {
            public override string Id {
                get { return AffectManager.GetCardId<Aeromancy>("block"); }
            }
        }
    }
}
